package manageflow

import (
	"hundsun.com/hsl/hschain/contract/native/manage/manageflow/exec"
	execcomm "hundsun.com/hsl/hschain/executor/common"
	"hundsun.com/hsl/hschain/protos/execute"
	common "hundsun.com/hsl/hschain/protos/manage"
)

// Node 执行节点，一个节点对应一个执行任务
type Node struct {
	nodeID              uint32
	execution           exec.Execution
	noneExecutionAction exec.Execution
	properties          *common.ExecProperties
}

// NewNode 新建一个执行节点
func NewNode(exec exec.Execution, properties *common.ExecProperties) *Node {
	var node = &Node{execution: exec, properties: properties}
	return node
}

// Execute 执行节点对应方法
func (n *Node) Execute(ctx *execcomm.ExecContent, gtx *execute.GroupedTransaction) error {
	if n.execution != nil {
		return n.execution.Run(ctx, gtx)
	} else if n.noneExecutionAction != nil {
		return n.noneExecutionAction.Run(ctx, gtx)
	}

	return nil
}
